//************************************************
//  *Author：jxx
//  *QQ：283591387
//  *自定义业务逻辑扩展
//************************************************
import { mapMutations } from 'vuex';
import extend from './q_install_requestExtend.js';
import options from './q_install_requestOptions.js';
export default function () {
	return {
		data() {
			let _options = options();
			_options.extend = extend;
			return {
				options: _options
			};
		},
		methods: {
			...mapMutations(['setSalesContractDataStore', 'setPageIDStore']),
			onInited() {
				this.editFormOptions.forEach((item) => {
					if (item.field == 'Sales_sub') {
						item.testVal = '点击选择销售单';
						item.required = true;
						item.focusUrl = '/pages/salesinfo/q_sales/q_sales';
					}
				});
			},
			formatter(row, column, index) {
				//自定义格式化
				// if(column.field=='xx'){
				//  return '<a style="color:red;">' + row[column.field] + '</a>';
				// }
				//return row[column.field]
			},
			rowClick(index, row, column) {
				//行点击事件(默认触发编辑)
				//行点击事件(默认触发编辑)
				// this.setPageIDStore(row.Install_request)
				// let url = '/pages/aftersaleinfo/q_install_request/Detail/Detail?salesinfo=' + row.Install_request;
				// uni.navigateTo({
				// 	url: url
				// });
				return false;
			},
			cellClick(index, row, column) {
				//单元格击事件(默认触发编辑)
				//仅onInited中设置：this.direction = "horizontal", this.columns的字段设置为click=true后生效
				return true;
			},
			rowButtons(index, row) {
				//列表显示的按钮
				//自定义按钮,仅onInited中设置：this.direction = "list"后生效
				let buttonList = [];
				let pages = getCurrentPages();
				// console.log('pages', pages);
				let prevPage = pages[pages.length - 2];
				if (
					pages.length >= 3 &&
					(prevPage.route == 'operationsinfo/q_install_request_notarize/q_install_request_notarize' || prevPage.route == 'pages/addPage/addPage') &&
					row.AuditStatus === 1 &&
					row.Install_status != 5
				) {
					buttonList.push({
						text: '选择安装申请单',
						type: 'success ',
						shape: 'circle'
					});
				}
				if (row.AuditStatus === 0) {
					buttonList.push({
						text: '审核',
						type: 'error',
						shape: 'circle'
					});
					if (buttonList.length != 2) {
						buttonList.push({
							text: '编辑',
							type: 'warning',
							shape: 'circle'
						});
					}
				} else {
					buttonList.push({
						text: '查看审核',
						type: 'primary',
						shape: 'circle'
					});
				}
				return buttonList;
			},
			rowButtonClick(btn, index, row) {
				//列表显示的按钮点击事件
				if (btn.text == '编辑') {
					uni.setStorageSync('q_install_request', row);
					const optionsObj = {
						// editFormFields: this.options.editFormFields,
						editFormOptions: this.options.editFormOptions,
						detailtable: this.options.table
					};
					uni.setStorageSync('optionsObj', JSON.stringify(optionsObj));
					uni.navigateTo({
						url: '/pages/addPage/addPage?biaoming=q_install_request&currentAction=Update&ID=Install_request&detailTableShow=false'
					});
					return;
				}
				if (btn.text == '选择安装申请单') {
					console.log('选中的数据row', row);
					// 清空明细表
					this.$store.commit('clearOperations_recycleList');
					const obj = JSON.stringify({
						Voucher_sub_install_request: row.Voucher_sub,
						Install_requestID: row.Install_request,
						Client: JSON.stringify(row.Client),
						Install_date: row.Install_date,
						Install_address: row.Install_address
					});
					uni.setStorageSync('obj', obj);
					uni.navigateBack();
					return;
				}
				this.setSalesContractDataStore({ workTable: 'q_install_request', tableKey: row.Install_request });
				try {
					uni.navigateTo({
						url: `/pages/aftersaleinfo/q_install_request/q_install_requestAduit?workTable=q_install_request&&tableKey=` + row.Install_request
					});
				} catch (e) {
					//TODO handle the exception
					console.log(e);
				}
			},
			searchBefore(params) {
				//查询前
				return true;
			},
			updateBefore(formData) {
				//更新保存前操作
				return true;
			},
			addBefore(formData) {
				//新建保存前操作
				return true;
			},
			searchFormOnChange(field, value) {
				//查询弹出框下拉框或日期选中事件
				//if(field=="字段"){
				// 	console.log(value)
				//}
			},
			editFormOnChange(field, value) {
				//新建编辑弹出框下拉框或日期选中事件
				//if(field=="字段"){
				// 	console.log(value)
				//}
			}
		}
	};
}
